<template>
  <div>
      <!-- 搜索栏 -->
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="操作人">
              <el-input v-model="formInline.operateUser" placeholder="请输入操作人"></el-input>
            </el-form-item>
            <el-form-item label="操作方法">
              <el-input v-model="formInline.operateMethod" placeholder="请输入操作方法"></el-input>
            </el-form-item>
            <el-form-item label="操作类">
              <el-input v-model="formInline.operateClass" placeholder="请输入操作类"></el-input>
            </el-form-item>
            <el-form-item label="操作方法传入的参数">
              <el-input v-model="formInline.operateArgs" placeholder="请输入操作方法传入的参数"></el-input>
            </el-form-item>
            <el-form-item label="方法返回值">
              <el-input v-model="formInline.operateReturn" placeholder="请输入方法返回值"></el-input>
            </el-form-item>
            <!-- 开始时间 -->
            <el-form-item class="block">
              <span class="demonstration">操作时间</span>
              <el-date-picker
                v-model="formInline.begin"
                type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择开始时间">
              </el-date-picker>
            </el-form-item>
            <!-- 结束时间 -->
            <el-form-item class="block">
              <span class="demonstration">操作时间</span>
              <el-date-picker
                v-model="formInline.end"
                type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择结束时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="getPageList" class="el-icon-search">查询</el-button>
            </el-form-item>
    </el-form>
    <!-- 主体表格 -->
    <el-table :data="operateLogList" style="width: 100%" class="table" border>
      <el-table-column prop="operateUser" label="操作人" width="70"></el-table-column>
      <el-table-column prop="operateMethod" label="操作方法" width="100"></el-table-column>
      <el-table-column prop="operateClass" label="操作类" width="200"></el-table-column>
      <el-table-column prop="operateArgs" label="操作方法传入的参数" width="350"></el-table-column>
      <el-table-column prop="operateReturn" label="方法的返回值" width="400"></el-table-column>
      <el-table-column label="操作耗时" width="100">
        <template slot-scope="scope">
          {{ scope.row.costTime }} ms
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="操作时间" width="170"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="danger" @click="del(scope.row)" class="el-icon-delete" size="mini">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页条 -->
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[5, 8, 10, 15, 20, 50, 100, 200, 500]"
        :page-size="5"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getPageOperateLog, deleteById } from '@/api/operateLog'
export default {
  name: 'OperatePage',
  data () {
    return {
      page: 1,
      pageSize: 5,
      total: null,
      operateLogList: [],
      formInline: {
        operateUser: null,
        operateMethod: null,
        operateClass: null,
        operateArgs: null,
        operateReturn: null,
        begin: null,
        end: null
      }

    }
  },
  created () {
    this.getPageList()
  },
  methods: {
    // 删除日志
    async del (row) {
      this.$confirm('确定要删除该记录吗?删除后将不可恢复！', '提示', {
        distinguishCancelAndClose: true,
        confirmButtonText: '确定删除',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        await deleteById(row.id)
        this.$message({
          type: 'success',
          message: '删除成功'
        })
        this.getPageList()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消删除'
        })
      })
    },
    // 分页条件查询
    async getPageList () {
      const { data } = await getPageOperateLog(this.page, this.pageSize, this.formInline.operateUser, this.formInline.operateMethod,
        this.formInline.operateClass, this.formInline.operateArgs, this.formInline.operateReturn, this.formInline.begin,
        this.formInline.end)
      this.operateLogList = data.records
      this.total = data.total
    },

    // 每页条数改变时触发
    handleSizeChange (pageSize) {
      this.pageSize = pageSize
      this.getPageList()
    },

    // 当前页码改变时触发
    handleCurrentChange (page) {
      this.page = page
      // 调用分页查询
      this.getPageList()
    }
  }
}
</script>

<style>

</style>
